package com.prs.crm.action.person;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;
import org.courser.ui.PaginationSupport;
import org.hibernate.criterion.DetachedCriteria;

import com.prs.crm.domain.person.RewardAndPunish;
import com.prs.crm.service.person.RewardAndPunishService;

public class RewardAndPunishAction extends BaseAction{

	private static final long serialVersionUID = 1L;
	private Integer[] ids;
	private RewardAndPunish rewardAndPunish;
	private RewardAndPunishService rewardAndPunishService;
	private PaginationSupport pagination;
	public Integer[] getIds() {
		return ids;
	}
	public void setIds(Integer[] ids) {
		this.ids = ids;
	}
	public RewardAndPunish getRewardAndPunish() {
		return rewardAndPunish;
	}
	public void setRewardAndPunish(RewardAndPunish rewardAndPunish) {
		this.rewardAndPunish = rewardAndPunish;
	}
	public RewardAndPunishService getRewardAndPunishService() {
		return rewardAndPunishService;
	}
	public void setRewardAndPunishService(
			RewardAndPunishService rewardAndPunishService) {
		this.rewardAndPunishService = rewardAndPunishService;
	}
	public PaginationSupport getPagination() {
		return pagination;
	}
	public void setPagination(PaginationSupport pagination) {
		this.pagination = pagination;
	}
	@Action("listRewardAndPunish")
	public String listRewardAndPunish(){
		DetachedCriteria criteria=this.getPaginationHelper().createQuery(RewardAndPunish.class);
		pagination=this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getRewardAndPunishService().listByPage(criteria, pagination));
		return SUCCESS;
	}
	
	@Action("editRewardAndPunish")
	public String editRewardAndPunish(){
		if(ids!=null){
			this.rewardAndPunish=this.getRewardAndPunishService().get(ids[0]);
		}
		return SUCCESS;
	}
	
	@Action("viewRewardAndPunish")
	public String viewRewardAndPunish(){
		if(ids!=null){
			this.rewardAndPunish=this.getRewardAndPunishService().get(ids[0]);
		}
		return SUCCESS;
	}
	@Action(value="saveRewardAndPunish",results={
			@Result(name="success",type="redirect",location="listRewardAndPunish"),
			@Result(name="error",type="chain",location="editRewardAndPunish")
	})
	public String saveRewardAndPunish(){
		this.getRewardAndPunishService().save(rewardAndPunish);
		return SUCCESS;
	}
	@Action(value="removeRewardAndPunish",results={
			@Result(name="success",type="redirect",location="listRewardAndPunish"),
			@Result(name="error",type="chain",location="listRewardAndPunish")
	})
	public String removeRewardAndPunish(){
		if(ids==null){
			this.addActionError("请选择一行进行操作！");
			return ERROR;
		}
		this.getRewardAndPunishService().batchRemove(ids);
		return SUCCESS;
	}
}
